﻿Public Class VSTYPECLASS
    Private VSID = Nothing
    Private VSDESC = Nothing
    Private LL = Nothing
    Private HL = Nothing
    Private UNIT = Nothing
    Private LSTORDER = Nothing
    Private MIN = Nothing
    Private MAX = Nothing
    Private vstypeStatus = Nothing
    Private F_OPD = Nothing
    Private F_IPD = Nothing
    Private F_ER = Nothing
    'Private selectMasprename = "SELECT PRENAME, FTPRENAME, FEPRENAME, STPRENAME, SEPRENAME, SEX, convert(bit, [STATUS]) FROM MASPRENAME"
    Private selectMasvstype = "SELECT `vsdesc` AS 'การวัดชีพ', `ll` AS 'ค่าต่ำสุด', `hl` AS 'ค่าสูงสุด', `unit` AS 'หน่วย', `lstorder` AS 'ตำแหน่งที่โชว์', `min` AS 'MIN', `max` AS 'MAX', `status` AS 'สถานะการเปิดใช้งาน', `vsid` AS 'รหัสการวัดชีพ', `f_opd` AS 'F_OPD', `f_ipd` AS 'F_IPD', `f_er` AS 'F_ER' FROM masvstype  "
    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection

    Property VSID_ As Integer
        Get
            Return VSID
        End Get
        Set(value As Integer)
            VSID = value
        End Set
    End Property

    Property VSDESC_ As String
        Get
            Return VSDESC
        End Get
        Set(value As String)
            VSDESC = value
        End Set
    End Property
    Property LL_ As Double
        Get
            Return LL
        End Get
        Set(value As Double)
            LL = value
        End Set
    End Property
    Property HL_ As Double
        Get
            Return HL
        End Get
        Set(value As Double)
            HL = value
        End Set
    End Property
    Property UNIT_ As String
        Get
            Return UNIT
        End Get
        Set(value As String)
            UNIT = value
        End Set
    End Property
    Property LSTORDER_ As Integer
        Get
            Return LSTORDER
        End Get
        Set(value As Integer)
            LSTORDER = value
        End Set
    End Property
    Property MIN_ As Integer
        Get
            Return MIN
        End Get
        Set(value As Integer)
            MIN = value
        End Set
    End Property
    Property MAX_ As Integer
        Get
            Return MAX
        End Get
        Set(value As Integer)
            MAX = value
        End Set
    End Property
    Property vstypeStatus_ As Boolean
        Get
            Return vstypeStatus
        End Get
        Set(value As Boolean)
            If value = True Then
                vstypeStatus = 1
            Else
                vstypeStatus = 0
            End If
        End Set
    End Property

    Property F_OPD_ As Boolean
        Get
            Return F_OPD
        End Get
        Set(value As Boolean)
            If value = True Then
                F_OPD = 1
            Else
                F_OPD = 0
            End If
        End Set
    End Property

    Property F_IPD_ As Boolean
        Get
            Return F_IPD
        End Get
        Set(value As Boolean)
            If value = True Then
                F_IPD = 1
            Else
                F_IPD = 0
            End If
        End Set
    End Property

    Property F_ER_ As Boolean
        Get
            Return F_ER_
        End Get
        Set(value As Boolean)
            If value = True Then
                F_ER = 1
            Else
                F_ER = 0
            End If
        End Set
    End Property

    Property selectMasvstype_ As String
        Get
            Return selectMasvstype
        End Get
        Set(value As String)

        End Set
    End Property

    'Public Function SEXCombobox() As DataTable
    '    connectlocal = conlocal.NewConnection()
    '    Return connectlocal.GetTable("SELECT SEX, SEXDESC FROM MASSEX WHERE [STATUS] = 1")
    'End Function

    Public Sub insertMasvstypeData()
        If VSDESC <> "" Then
            If TypeOf VSDESC Is String Then
                If connect.GetTable("SELECT `vsdesc` FROM masvstype WHERE `vsdesc` = '" & VSDESC & "'").Rows.Count > 0 Then
                    MsgBox("มีข้อมูลนี้อยู่ในระบบแล้ว")
                Else
                    Try
                        connect = CONDB.NewConnection()
                        'connectlocal = conlocal.NewConnection()
                        Dim VSID As Integer
                        VSID = connect.ExecuteScalar("INSERT INTO masvstype (`vsdesc`,`ll`,`hl`,`unit`,`lstorder`,`min`,`max`,`status`) VALUES ('" & VSDESC & "','" & LL & "','" & HL & "','" & UNIT & "','" & LSTORDER & "', " & MIN & "'," & MAX & "','" & vstypeStatus & "'); SELECT LAST_INSERT_ID();")
                        'connectlocal.ExecuteNonQuery("INSERT INTO MASPENNAME (PENNAME,PENLNAME, SEX, STATUS) VALUES ('" & PENNAME & "','" & PENLNAME & "','" & SEX & "', '" & pennameStatus & "')")
                        MsgBox("ท่านได้ทำการเพิ่มข้อมูลเรียบร้อยแล้ว")
                    Catch ex As Exception
                        MsgBox("มีข้อมูลนี้อยู่ในระบบอยู่แล้ว" & vbCrLf & ex.Message)
                    End Try
                    connect.Dispose()
                End If
            Else
                MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
            End If
        Else
            MsgBox("ท่านต้องทำการกรอกข้อมูลให้ครบถ้วน")
        End If
    End Sub

    Public Sub editMasvstypeData()
        If VSID > 0 And VSDESC <> "" Then
            If TypeOf VSDESC Is String Then
                Try
                    connect = CONDB.NewConnection()

                    Dim sql As String

                    If VSID > 8 Then
                        sql = ("UPDATE masvstype SET `vsdesc` = '" & VSDESC & "', `ll` = '" & LL & "' , `hl` = '" & HL & "',`unit` = '" & UNIT & "',`lstorder` = '" & LSTORDER & "',`min` = '" & MIN & "',`max` = '" & MAX & "', `status` = '" & vstypeStatus & "', `f_opd` = '" & F_OPD & "', `f_ipd` = '" & F_IPD & "', `f_er` = '" & F_ER & "' WHERE `vsid` = '" & VSID & "'")
                    Else
                        sql = ("UPDATE masvstype SET `ll` = '" & LL & "' , `hl` = '" & HL & "',`unit` = '" & UNIT & "',`lstorder` = '" & LSTORDER & "',`min` = '" & MIN & "',`max` = '" & MAX & "' WHERE `vsid` = '" & VSID & "'")
                    End If

                    connect.ExecuteNonQuery(sql)

                    MsgBox("ท่านได้ทำการแก้ไขข้อมูลเรียบร้อยแล้ว")
                Catch ex As Exception
                    MsgBox("มีข้อมูลนี้อยู่ในระบบแล้ว" & vbCrLf & ex.Message)
                End Try
                connect.Dispose()
            Else
                MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
            End If
        Else
            MsgBox("ท่านต้องทำการกรอกข้อมูลให้ครบถ้วน")
        End If
    End Sub
End Class
